package com.corona.game.util;

import com.badlogic.gdx.audio.Music;
import com.corona.game.util.audio.AudioLoader;
import gme.VGMPlayer;

/* loaded from: pokewilds.jar:com/pkmngen/game/util/LinkedMusic.class */
public class LinkedMusic implements Music {
    Music music1;
    Music music2;
    Music currMusic;
    public static VGMPlayer gbsPlayer = new VGMPlayer(44100);
    public Type type;

    /* loaded from: pokewilds.jar:com/pkmngen/game/util/LinkedMusic$Type.class */
    public enum Type {
        NORMAL,
        GME
    }

    public LinkedMusic(String m1, String m2) {
        this.type = Type.NORMAL;
        if (m1.contains("pkmnmansion1") || m2.contains("pkmnmansion1")) {
            this.type = Type.GME;
            try {
                gbsPlayer.loadFile("DMG-APEE-USA.gbs", "DMG-APEE-USA.gbs");
                gbsPlayer.startTrack(38, 100);
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else {
            this.music1 = AudioLoader.loadMusic(m1 + ".ogg");
            this.music1.setLooping(false);
            this.currMusic = this.music1;
            if (!m2.equals("")) {
                this.music1.setOnCompletionListener(new OnCompletionListener() { // from class: com.corona.game.util.LinkedMusic.1
                    @Override // com.badlogic.gdx.audio.Music.OnCompletionListener
                    public void onCompletion(Music music) {
                        LinkedMusic.this.music2.play();
                        LinkedMusic.this.currMusic = LinkedMusic.this.music2;
                    }
                });
                this.music2 = AudioLoader.loadMusic(m2 + ".ogg");
                this.music2.setLooping(true);
                this.music2.play();
                this.music2.pause();
            }
        }
    }

    @Override // com.badlogic.gdx.audio.Music
    public void play() {
        if (this.type == Type.GME) {
            try {
                if (!gbsPlayer.isPlaying()) {
                    gbsPlayer.play();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else {
            this.currMusic.play();
        }
    }

    @Override // com.badlogic.gdx.audio.Music
    public void pause() {
        if (this.type == Type.GME) {
            try {
                if (gbsPlayer.isPlaying()) {
                    gbsPlayer.pause();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else {
            this.currMusic.pause();
        }
    }

    @Override // com.badlogic.gdx.audio.Music
    public void stop() {
        if (this.type == Type.GME) {
            try {
                gbsPlayer.stop();
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else {
            if (this.music2 != null) {
                this.music2.stop();
            }
            this.music1.stop();
            this.currMusic = this.music1;
        }
    }

    @Override // com.badlogic.gdx.audio.Music
    public boolean isPlaying() {
        if (this.type == Type.GME) {
            return gbsPlayer.isPlaying();
        }
        return this.currMusic.isPlaying();
    }

    @Override // com.badlogic.gdx.audio.Music
    public void setLooping(boolean isLooping) {
        if (this.type == Type.GME) {
            System.out.println("hi");
        } else {
            this.currMusic.setLooping(isLooping);
        }
    }

    @Override // com.badlogic.gdx.audio.Music
    public boolean isLooping() {
        if (this.type == Type.GME) {
            return true;
        }
        return this.currMusic.isLooping();
    }

    @Override // com.badlogic.gdx.audio.Music
    public void setVolume(float volume) {
        if (this.type == Type.GME) {
            try {
                gbsPlayer.setVolume((double) volume);
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else {
            if (this.music2 != null) {
                this.music2.setVolume(volume);
            }
            this.music1.setVolume(volume);
        }
    }

    @Override // com.badlogic.gdx.audio.Music
    public float getVolume() {
        if (this.type == Type.GME) {
            return (float) gbsPlayer.getVolume();
        }
        return this.currMusic.getVolume();
    }

    @Override // com.badlogic.gdx.audio.Music
    public void setPan(float pan, float volume) {
        if (this.type != Type.GME) {
            this.currMusic.setPan(pan, volume);
        }
    }

    @Override // com.badlogic.gdx.audio.Music
    public void setPosition(float position) {
        if (this.type != Type.GME) {
            this.currMusic.setPosition(position);
        }
    }

    @Override // com.badlogic.gdx.audio.Music
    public float getPosition() {
        if (this.type == Type.GME) {
            return 0.0f;
        }
        return this.currMusic.getPosition();
    }

    @Override // com.badlogic.gdx.audio.Music, com.badlogic.gdx.utils.Disposable
    public void dispose() {
        if (this.type != Type.GME) {
            this.music1.dispose();
            if (this.music2 != null) {
                this.music2.dispose();
            }
        }
    }

    @Override // com.badlogic.gdx.audio.Music
    public void setOnCompletionListener(OnCompletionListener listener) {
        if (this.type != Type.GME) {
            this.currMusic.setOnCompletionListener(listener);
        }
    }
}
